﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WDutils;

namespace WD.Classes
{
    public class BasicObject
    {
        protected Int64 intCreatedOn;
        protected Int64 intModifiedOn;
        protected Int64 intDeletedOn;

        protected Dictionary<string, string> dictData;
        
        /// <summary>
        /// Basic constructor.
        /// </summary>
        public BasicObject() 
        {
            this.dictData = new Dictionary<string,string>();
            this.intCreatedOn = Utils.Unix.GetCurrentUnixTimestampSeconds();
            this.intModifiedOn = Utils.Unix.GetCurrentUnixTimestampSeconds();
        }

        public BasicObject(Dictionary<string, string> dictData) 
        {
            this.dictData = dictData;
            this.intCreatedOn = Utils.Unix.GetCurrentUnixTimestampSeconds();
            this.intModifiedOn = Utils.Unix.GetCurrentUnixTimestampSeconds();
        }

        public Dictionary<string, string> getDictData()
        {
            return this.dictData;
        }

        public void setDictData(Dictionary<string, string> dictData)
        {
            this.dictData = dictData;
        }

        #region Setter and Getter for created_on column
        /// <summary>
        /// Setter for created_on column
        /// </summary>
        /// <param name="intCreatedOn"></param>
        public void setCreatedOn(Int64 intCreatedOn)
        {
            this.intCreatedOn = intCreatedOn;
        }

        /// <summary>
        /// Getter for created_on column
        /// </summary>
        /// <returns>Return Int64 Unix timestamp representing the "created on" datetime</returns>
        public Int64 getCreatedOn()
        {
            return this.intCreatedOn;
        }
        #endregion

        #region Setter and Getter for modified_on column
        /// <summary>
        /// Setter for modified_on column
        /// </summary>
        /// <param name="intModifiedOn"></param>
        public void setModifiedOn(Int64 intModifiedOn)
        {
            this.intModifiedOn = intModifiedOn;
        }

        /// <summary>
        /// Getter for modified_on column
        /// </summary>
        /// <returns>Return Int64 Unix timestamp representing the "modified on" datetime</returns>
        public Int64 getModifiedOn()
        {
            return this.intModifiedOn;
        }
        #endregion

        #region Setter and Getter for deleted_on column
        /// <summary>
        /// Setter for deleted_on column
        /// </summary>
        /// <param name="intDeletedOn"></param>
        public void setDeletedOn(Int64 intDeletedOn)
        {
            this.intDeletedOn = intDeletedOn;
        }

        /// <summary>
        /// Getter for deleted_on column
        /// </summary>
        /// <returns>Return Int64 Unix timestamp representing the "deleted on" datetime</returns>
        public Int64 getDeletedOn()
        {
            return this.intDeletedOn;
        }
        #endregion

        #region Special getters for CreatedOn ModifiedOn and DeletedOn for human readable form
        /// <summary>
        /// Getter for CreatedOn in DateTime format
        /// </summary>
        /// <returns>Return creation DateTime object converted from unix time</returns>
        public DateTime getCreatedOnDateTime()
        {
            return Utils.Unix.DateTimeFromUnixTimestampSeconds(this.intCreatedOn);
        }

        /// <summary>
        /// Getter for ModifiedOn in DateTime format
        /// </summary>
        /// <returns>Return modification DateTime object converted from unix time</returns>
        public DateTime getModifiedOnDateTime()
        {
            return Utils.Unix.DateTimeFromUnixTimestampSeconds(this.intModifiedOn);
        }

        /// <summary>
        /// Getter for DeletedOn in DateTime format
        /// </summary>
        /// <returns>Return deletion DateTime object converted from unix time</returns>
        public DateTime getDeletedOnDateTime()
        {
            return Utils.Unix.DateTimeFromUnixTimestampSeconds(this.intDeletedOn);
        }

        public string getDeletedOnDateTime2String()
        {
            if (this.intDeletedOn == 0) return "-";
            return Utils.Unix.DateTimeFromUnixTimestampSeconds(this.intDeletedOn).ToLocalTime().ToString();
        }


        #endregion

    }
}
